//
//  HSTopicListCell.m
//  HolyShit
//
//  Created by Robin on 2017/4/4.
//  Copyright © 2017年 HolyShit. All rights reserved.
//

#import "HSTopicListCell.h"
#import "NSDate+MY_DateFormat.h"

@interface HSTopicListCell ()

@property (nonatomic, strong) UIImageView *headImgV;
@property (nonatomic, strong) UILabel *nameLb;
@property (nonatomic, strong) UILabel *timeLb;
@property (nonatomic, strong) UILabel *replyLb;
@property (nonatomic, strong) UILabel *titleLb;
@property (nonatomic, strong) UIView *bottomV;

@end

@implementation HSTopicListCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self commonInit];
    }
    return self;
}

- (void)commonInit
{
    self.backgroundColor = WHITE_COLOR;
    self.width = ScreenWidth;
    [self my_setSelectedBg];
    
    self.headImgV = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 40, 40) imageType:MYImageTypeSmallHead];
    [self addSubview:self.headImgV];
    [self.headImgV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.mas_equalTo(10);
        make.width.height.mas_equalTo(40);
    }];
    
    self.nameLb = [UILabel labelWithFont:MYFont(Font28) color:HEXCOLOR(HSColorBlack)];
    [self addSubview:self.nameLb];
    [self.nameLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.headImgV.mas_right).offset(8);
        make.top.equalTo(self.headImgV);
    }];
    
    self.timeLb = [UILabel labelWithFont:MYFont(Font24) color:HEXCOLOR(HSColorGray)];
    [self addSubview:self.timeLb];
    [self.timeLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.nameLb);
        make.bottom.equalTo(self.headImgV);
    }];
    
    self.replyLb = [UILabel labelWithFont:MYFont(Font26) color:HEXCOLOR(HSColorRed)];
    [self addSubview:self.replyLb];
    [self.replyLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.nameLb);
        make.right.mas_equalTo(-9);
    }];
    
    self.titleLb = [UILabel labelWithFont:MYFont(Font32) color:HEXCOLOR(HSColorBlack)];
    self.titleLb.numberOfLines = 0;
    [self addSubview:self.titleLb];
    [self.titleLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.headImgV);
        make.top.equalTo(self.headImgV.mas_bottom).offset(13);
        make.right.mas_equalTo(-9);
    }];
    
    self.bottomV = [UIView new];
    self.bottomV.backgroundColor = HEXCOLOR(HSColorBgLight);
    [self addSubview:self.bottomV];
    [self.bottomV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.mas_equalTo(0);
        make.top.equalTo(self.titleLb.mas_bottom).offset(13);
        make.height.mas_equalTo(10);
    }];
}

- (void)setModel:(HSForumAttributesModel *)model
{
    _model = model;
    [self.headImgV my_setImage:model.avatarUrl];
    self.nameLb.text = model.username;
    NSDate *date = [NSDate dateWithISOFormatString:model.startTime];
    self.timeLb.text = [date my_getDisplayTimeString];
    self.replyLb.text = [NSString stringWithFormat:@"回复数：%lu",model.commentsCount];
    self.titleLb.text = model.title;
    if (model.cellHeight < 1) {
        [self layoutSubviews];
        model.cellHeight = self.bottomV.bottom;
    }
}

@end
